### contains

Checks if `option` is the `Some` variant and contains the given value.


```ts
function contains<A>(option: Option<A>, value: any): boolean
function contains<A>(value: any): (option: Option<A>) => boolean
```

```ts
pipe(O.fromNullable([3, 6, 9]), O.flatMap(A.head), O.contains(3)) // → true
pipe(O.fromNullable([3, 6, 9]), O.flatMap(A.get(1)), O.contains(3)) // → false
```

### filter

Returns `Some(value)` if `option` is `Some(value)` and the result of `predicateFn` is truthy, otherwise, returns `None`.


```ts
function filter<A>(option: Option<A>, predicateFn: (value: A) => boolean): Option<A>
function filter<A>(predicateFn: (value: A) => boolean): (option: Option<A>) => Option<A>
```

```ts
pipe(
  O.fromNullable([3, 6, 9]),
  O.flatMap(A.get(0)),
  O.filter(value => value === 3),
) // → Some(3)

pipe(
  O.fromNullable([3, 6, 9]),
  O.flatMap(A.get(0)),
  O.filter(value => value === 0),
) // → None
```

### flatMap

Returns the result of `mapFn` (it must have a return type of `Option`) if `option` is `Some(value)`, otherwise, returns `None`.


```ts
function flatMap<A, B>(option: Option<A>, mapFn: (value: A) => Option<B>): Option<B>
function flatMap<A, B>(mapFn: (value: A) => Option<B>): (option: Option<A>) => Option<B>
```

```ts
pipe(
  O.fromNullable('hello'),
  O.flatMap(value => {
    return value.endsWith('lo') ? O.Some(`${value} world!`) : O.None
  }),
) // → Some('hello world!')
```

### fromExecution

Returns `Some(value)` (`value` is the result of `fn`) if `fn` didn't throw an error, otherwise, returns `None`.


```ts
function fromExecution<A>(fn: () => A): Option<ExtractValue<A>>
```

```ts
type User = { readonly name: string }
const parseJSON = <T>(value: string) => () => JSON.parse(value) as T
const okJSON = `{"name": "John"}`
const badJSON = `{name": John}`

O.fromExecution(parseJSON<User>(okJSON)) // → Some({ name: 'John' })

O.fromExecution(parseJSON<User>(badJSON)) // → None
```

### fromFalsy

Returns `Some(value)` if the provided value is not falsy, otherwise, returns `None`.


```ts
function fromFalsy<A>(value: A): Option<ExtractValue<A>>
```

```ts
O.fromFalsy(1) // → Some(1)
O.fromFalsy('hello world') // → Some('hello world')
O.fromFalsy([]) // → Some([])
O.fromFalsy(0) // → None
O.fromFalsy('') // → None
```

### fromNullable

Returns `Some(value)` if the provided value is non-nullable, otherwise, returns `None`.


```ts
function fromNullable<A>(value: A): Option<ExtractValue<A>>
```

```ts
O.fromNullable(1) // → Some(1)
O.fromNullable('hello world') // → Some('hello world')
O.fromNullable([]) // → Some([])
O.fromNullable(false) // → Some(false)
O.fromNullable(null) // → None
O.fromNullable(undefined) // → None
```

### fromPredicate

Returns `Some(value)` if the given predicate function returns `true`, otherwise, returns `None`.


```ts
function fromPredicate<A>(value: A, predicateFn: (value: NonNullable<A>) => boolean): Option<ExtractValue<A>>
function fromPredicate<A>(predicateFn: (value: NonNullable<A>) => boolean): (value: A) => Option<ExtractValue<A>>
```

```ts
O.fromPredicate(
  [1, 2, 3],
  A.some(x => x === 2),
) // → Some([1, 2, 3])

O.fromPredicate(
  [1, 2, 3],
  A.some(x => x === 4),
) // → None
```

### fromPromise

Returns `Some(value)` if `promise` is resolved successfully, otherwise, returns `None`.


```ts
function fromPromise<A>(promise: Promise<A>): Promise<Option<ExtractValue<A>>>
```

```ts
await O.fromPromise(Promise.resolve('hello world')) // → Some('hello world')
await O.fromPromise(Promise.reject('oops')) // → None
```

### getExn

Returns `value` if `option` is `Some(value)`, otherwise, throws an exception.


```ts
function getExn<A>(option: Option<A>): A | never
```

```ts
pipe(
  O.fromNullable('hello'),
  O.map(value => `${value} world!`),
  O.getExn,
) // → 'hello world!'
```

### getWithDefault

Returns `value` if `option` is `Some(value)`, otherwise, returns a default value.


```ts
function getWithDefault<A>(option: Option<A>, defaultValue: NonNullable<A>): A
function getWithDefault<A>(defaultValue: NonNullable<A>): (option: Option<A>) => A
```

```ts
pipe(
  O.fromNullable('hello'),
  O.map(value => `${value} world!`),
  O.getWithDefault('error'),
) // → 'hello world!'

pipe(
  O.fromNullable(null),
  O.map(value => `${value} world!`),
  O.getWithDefault('error'),
) // → 'error'
```

### isNone

Returns `true` if the provided `option` is `None`, otherwise, returns `false`.


```ts
function isNone<A>(option: Option<A>): option is Option<never>
```

```ts
O.isNone(O.None) // → true
pipe(O.fromNullable(null), O.isNone) // → true
O.isNone(O.Some('hello world!')) // → false
pipe(O.fromNullable('hello world!'), O.isNone) // → false
```

### isSome

Returns `true` if the provided `option` is `Some(value)`, otherwise, returns `false`.


```ts
function isSome<A>(option: Option<A>): option is Option<A>
```

```ts
O.isSome(O.Some('hello world!')) // → true
pipe(O.fromNullable('hello world!'), O.isSome) // → true
O.isSome(O.None) // → false
pipe(O.fromNullable(null), O.isSome) // → false
```

### map

Returns the result of `mapFn` if `option` is `Some(value)`, otherwise, returns `None` and `mapFn` is not called.


```ts
function map<A, B>(option: Option<A>, mapFn: (value: A) => NonNullable<B>): Option<B>
function map<A, B>(mapFn: (value: A) => NonNullable<B>): (option: Option<A>) => Option<B>
```

```ts
pipe(
  O.fromNullable([1, 2, 3]),
  O.flatMap(A.get(0)),
  O.map(n => `${n}. hello world!`),
) // → Some('1. hello world!')

pipe(
  O.fromNullable([]),
  O.flatMap(A.get(0)),
  O.map(n => `${n}. hello world!`),
) // → None
```

### mapNullable

Returns `Some(value)` if the result of `mapFn` is non-nullable, otherwise, returns `None`.


```ts
function mapNullable<A, B>(option: Option<A>, mapFn: (value: A) => B | null | undefined): Option<ExtractValue<B>>
function mapNullable<A, B>(mapFn: (value: A) => B | null | undefined): (option: Option<A>) => Option<ExtractValue<B>>
```

```ts
pipe(
  O.fromNullable([1, 2, 3]),
  O.mapNullable(value => value[0]),
) // → Some(1)

pipe(
  O.fromNullable([undefined, 2, 3]),
  O.mapNullable(value => value[0]),
) // → None
```

### mapWithDefault

Returns the result of `mapFn` if `option` is `Some(value)`, otherwise, returns a default value.


```ts
function mapWithDefault<A, B>(option: Option<A>, defaultValue: NonNullable<B>, mapFn: (value: A) => B): B
function mapWithDefault<A, B>(defaultValue: NonNullable<B>, mapFn: (value: A) => B): (option: Option<A>) => B
```

```ts
pipe(
  O.fromNullable(['hello']),
  O.flatMap(A.get(0)),
  O.mapWithDefault('default value', value => `${value} world!`),
) // → 'hello world!'

pipe(
  O.fromNullable([]),
  O.flatMap(A.get(0)),
  O.mapWithDefault('default value', value => `${value} world!`),
) // → 'default value'
```

### match

Returns the result of `someFn` if `option` is `Some(value)`, otherwise, returns the result of `noneFn`.


```ts
function match<A, B>(option: Option<A>, someFn: (value: A) => B, noneFn: () => B): B
function match<A, B>(someFn: (value: A) => B, noneFn: () => B): (option: Option<A>) => B
```

```ts
pipe(
  O.fromNullable(['hello', 'world', 'lorem', 'ipsum']),
  O.flatMap(A.takeExactly(2)),
  O.map(A.join(' ')),
  O.match(
    str => `${str}!`,
    () => 'oops!',
  ),
) // → 'hello world!'

pipe(
  O.fromNullable([]),
  O.flatMap(A.takeExactly(2)),
  O.map(A.join(' ')),
  O.match(
    str => `${str}!`,
    () => 'oops!',
  ),
) // → 'oops!'
```

### tap

Applies a side-effect function to the value in `Some`, and returns the original `option`.


```ts
function tap<A>(option: Option<A>, someFn: (value: A) => void): Option<A>
function tap<A>(someFn: (value: A) => void): (option: Option<A>) => Option<A>
```

```ts
pipe(
  O.fromNullable(['hello', 'world']),
  O.flatMap(A.get(1)),
  O.tap(str => {
    console.log(str) // ⬅️ 'world'
  }),
  O.getWithDefault(''),
) // → 'world'
```

### toNullable

Returns `value` if `option` is `Some(value)`, otherwise, returns `null`.


```ts
function toNullable<A>(option: Option<A>): A | null
```

```ts
pipe(
  O.fromNullable(['hello', 'world']),
  O.flatMap(A.takeExactly(2)),
  O.toNullable,
) // → ['hello', 'world']

pipe(O.fromNullable([]), O.flatMap(A.takeExactly(2)), O.toNullable) // → null
```

### toResult

Returns `Ok(value)` if `option` is `Some(value)`, otherwise, returns `Error(errorValue)`, both `Ok` and `Error` come from the `Result` type.


```ts
function toResult<A, B>(option: Option<A>, errorValue: NonNullable<B>): Result<A, B>
function toResult<A, B>(errorValue: NonNullable<B>): (option: Option<A>) => Result<A, B>
```

```ts
pipe(
  O.fromNullable(['hello', 'world']),
  O.flatMap(A.takeExactly(2)),
  O.toResult('oops!'),
) // → R.Ok(['hello', 'world'])

pipe(
  O.fromNullable([]),
  O.flatMap(A.takeExactly(2)),
  O.toResult('oops!'),
) // → R.Error('oops!')
```

### toUndefined

Returns `value` if `option` is `Some(value)`, otherwise, returns `undefined`.


```ts
function toUndefined<A>(option: Option<A>): A | undefined
```

```ts
pipe(
  O.fromNullable(['hello', 'world']),
  O.flatMap(A.takeExactly(2)),
  O.toUndefined,
) // → ['hello', 'world']

pipe(O.fromNullable([]), O.flatMap(A.takeExactly(2)), O.toUndefined) // → undefined
```

### zip

Combines two Options into a single Option containing a tuple of their values, if both Options are `Some` variants, otherwise, returns `None`.


```ts
function zip<A, B>(sndOption: Option<B>): (fstOption: Option<A>) => Option<readonly [A, B]>
function zip<A, B>(fstOption: Option<A>, sndOption: Option<B>): Option<readonly [A, B]>
```

```ts
pipe(O.fromNullable('hello'), O.zip(O.fromNullable('world'))) // → Some(['hello', 'world'])
```

### zipWith

Combines two Options into a single Option. The new value is produced by applying the given function to both values, if both Options are `Some` variants, otherwise, returns `None`.


```ts
function zipWith<A, B, C>(
    fstOption: Option<A>,
    sndOption: Option<B>,
    mapFn: (arg0: A, arg1: B) => Option<C>
): Option<C>
function zipWith<A, B, C>(sndOption: Option<B>, mapFn: (arg0: A, arg1: B) => Option<C>): (fstOption: Option<A>) => Option<C>
```

```ts
pipe(
  O.fromNullable('hello'),
  O.zipWith(O.fromNullable('world'), S.concat),
) // → Some('helloworld')
```